var h = Object.defineProperty;
var a = (e, t, i) =>
  t in e
    ? h(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i })
    : (e[t] = i);
var l = (e, t, i) => (a(e, typeof t != 'symbol' ? t + '' : t, i), i);
class o {
  constructor() {
    l(this, 'lineStarts', []);
    /**
     * Should be called in ascending order. Otherwise, call
     * `lineCounter.lineStarts.sort()` before calling `linePos()`.
     */
    l(this, 'addNewLine', t => this.lineStarts.push(t));
    /**
     * Performs a binary search and returns the 1-indexed { line, col }
     * position of `offset`. If `line === 0`, `addNewLine` has never been
     * called or `offset` is before the first known newline.
     */
    l(this, 'linePos', t => {
      let i = 0,
        n = this.lineStarts.length;
      for (; i < n; ) {
        const s = (i + n) >> 1;
        this.lineStarts[s] < t ? (i = s + 1) : (n = s);
      }
      if (this.lineStarts[i] === t) return { line: i + 1, col: 1 };
      if (i === 0) return { line: 0, col: t };
      const r = this.lineStarts[i - 1];
      return { line: i, col: t - r + 1 };
    });
  }
}
export { o as LineCounter };
